class MyPage extends BaseList {
    constructor(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl) {
        super(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl);
    }
    SetCriterion(item) {
        // 设置材料检索条件       
        item['Limit'] = parseInt($("#page-size").val());
        item['PageIndex'] = parseInt($("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page"));
        item['OrderBy'] = _Instance.orderby;

        item['MaterialNameFilterValue'] = formatNullInputValue($.trim($("#MaterialNameFilterValue").val()));
        item['MaterialNoFilterValue'] = formatNullInputValue($.trim($("#MaterialNoFilterValue").val()));
        item['StyleNoFilterValue'] = formatNullInputValue($.trim($("#StyleNoFilterValue").val()));
        item['Begin'] = formatNullInputValue($.trim($("#Begin").val()));
        item['End'] = formatNullInputValue($.trim($("#End").val()));
        item['CheckedStatus'] = parseInt($("#CheckedStatus").val()) === -1 ? null : parseInt($("#CheckedStatus").val());
        if ($("#RoleName").val().indexOf("系统管理员") !== 0) {
            item['OperatedBy'] = parseInt($("#UserId").val());
        }
        return item;
    }
    GetFilter(pageIndex) {
        let item = super.GetFilter(pageIndex);
        // 设置条件
        item = this.SetCriterion(item);

        return JSON.stringify(item);
    }
    FetchByFilter() {
        this.FetchForPage(1);
    }
    FetchAll() {
        $("#Begin").val("");
        $("#End").val("");
        $("#MaterialNoFilterValue").val("");
        $("#MaterialNameFilterValue").val("");
        $("#StyleNoFilterValue").val("");
        $("#CheckedStatus").val("-1");
        $("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page", 1);

        this.$pagination.attr("_msh_page", 1);
        this.FetchForPage(1);
    }
    EmptyTableContent() {
        $("#tabData01 tbody").empty();
        this.$pagination.attr("_msh_page", 1);
    }
    SetTableContent(result) {
        $("#tabData01 tbody").empty();

        let content_01 = '';
        for (let i = 0; i < result.length; i++) {
            let id = result[i].headerId;
            content_01 = '<tr _mash_id="' + id + '">';
            content_01 += '<td class="column__action"><span title="编辑" class="edit" onclick="_Instance.DoEdit($(this));"><i class="fa-all fa-pencil fa-1"></i></span></td>';
            if (result[i].checkedBy !== null) {
                content_01 += '<td></td>';
            } else {
                // 删除权限控制
                if ($("#ActionAcl_4").length === 0 || parseInt($("#ActionAcl_4").val() === 0)) {
                    content_01 += '<td></td>';
                } else {
                    // 被采购引用也不能删除
                    if (result[i].quotedFlag === false) {
                        if ((parseInt($("#UserId").val()) === parseInt(result[i].scheduledBy)) || ($("#RoleName").val().indexOf("系统管理员") !== -1)) {
                            content_01 += '<td class="column__action"><span title="删除" class="trash" onclick="_Instance.DoDelete($(this));"><i class="fa-all fa-trash-o fa-1"></i></span></td>';
                        } else {
                            content_01 += '<td></td>';
                        }
                    } else {
                        content_01 += '<td></td>';
                    }
                }
            }
            content_01 += '<td>' + formatNullData(result[i].billNo) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].feedingTypeName) + '</td>';
            // 有审核人则是审核中的状态，否则未审核状态
            if (result[i].checkedBy === null) {
                content_01 += '<td style="text-align:center;"><span class="c2"></span></td>';
            } else {
                if (parseInt(result[i].checkedStatus) === 1) {
                    // 最终审核
                    content_01 += '<td style="text-align:center;"><span class="c1"><span></td>';
                } else {
                    content_01 += '<td style="text-align:center;"><span class="c3"></span></td>';
                }
            }
            let _isFinished = '';
            if (result[i].poOpeningRows === true) {
                _isFinished = "<span class='c1'><span>";
            } else {
                if (result[i].quotedFlag === false) {
                    _isFinished = "<span class='c2'><span>";
                } else {
                    _isFinished = "<span class='c3'><span>";   // 表示完成一部分，还在采购中
                }
            }
            content_01 += '<td style="text-align:center;">' + _isFinished + '</td>';
            content_01 += '<td>' + formatNullData(result[i].scheduledDate) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].scheduledByName) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].updatedByName) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].updatedDate) + '</td>';
            //content_01 += '<td>' + formatNullData(result[i].checkedByName) + '</td>';
            content_01 += '<td style="border-right: none;">' + formatNullData(result[i].description) + '</td>';
            content_01 += '</tr>';

            $("#tabData01 tbody").append(content_01);
            content_01 = '';
        }
        setOneTableRowColor("tabData01");
    }
    DoInsert() {
        super.DoInsert();
        location.assign(parent.basePath + '/tech/mrp/feeding/1/0/' + 'edit.html');
    }
    DoEdit($self) {
        super.DoEdit();
        // 设置当前检索后的数据列表标识数组
        let _arrayResultList = new Array();
        $("#tabData01 tbody tr").each(function (index) {
            _arrayResultList.push($(this).attr("_mash_id"));
        });
        $.cookie(this.cokieListResult, _arrayResultList.join(","));
        location.assign(parent.basePath + '/tech/mrp/feeding/2/' + $self.parent().parent().attr("_mash_id") + '/edit.html');
    }
    DoDelete($self) {
        let _params = super.GetFilter(this.$pagination.attr("_msh_page"));
        _params['HeaderId'] = $self.parent().parent().attr("_mash_id");
        _params['DeletedBy'] = $("#UserId").val();
        _params['DeletedBillNo'] = $self.parent().parent().find("td").eq(2).text();

        super.DoDelete(_params, (_this, data) => {
            if (data.Success) {
                _this.BuildDataTable(data);
            } else {
                _this.EmptyTableContent();
            }
            ShowSuccessMessagePanel("删除成功。");
        });
    }
    SaveFilters() {
        let _filters = new Array();
        _filters.push($("#Begin").val());
        _filters.push($("#End").val());
        _filters.push($("#MaterialNoFilterValue").val());
        _filters.push($("#MaterialNameFilterValue").val());
        _filters.push($("#StyleNoFilterValue").val());
        _filters.push($("#CheckedStatus").val());
        $.cookie("mrp_feeding_list_fiters", _filters.join(","));
    }
    RestoreFilters() {
        if ($.cookie("mrp_feeding_list_fiters") !== undefined && this.flag !== 0) {
            let _filters = $.cookie("mrp_feeding_list_fiters").split(',');
            $("#Begin").val(_filters[0]);
            $("#End").val(_filters[1]);
            $("#MaterialNoFilterValue").val(_filters[2]);
            $("#MaterialNameFilterValue").val(_filters[3]);
            $("#StyleNoFilterValue").val(_filters[4]);
            $("#CheckedStatus").val(_filters[5]);
        } else {
            $("#Begin").val("");
            $("#End").val("");
            $("#MaterialNoFilterValue").val("");
            $("#MaterialNameFilterValue").val("");
            $("#StyleNoFilterValue").val("");
            $("#CheckedStatus").val("-1");
        }
    }
}

var _Instance = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    let flag = jQuery.url.param("flag") === undefined ? 0 : jQuery.url.param("flag");
    $("#page-size").val($.cookie("mrp_feeding_list_pagesize") === undefined ? 15 : $.cookie("mrp_feeding_list_pagesize"));
    // 删除已经保存的检索后的数据列表标识数组
    $.cookie("mrp_feeding_list_result", null);

    _Instance = new MyPage(0, null, flag,
            $("#page-size"),
            $("abbr.page_indicator_block,#wrapper__navbar"),
            "mrp_feeding_list_pagesize",
            "mrp_feeding_list_pageindex",
            "mrp_feeding_list_result",
            "/tech/mrp/feeding/fetchForPage.html",
            "/tech/mrp/feeding/header/delete.html");

    //设置分页控制 （操作区域）
    $("#wrapper__navbar").swPagination({
        link_string: '/?page={page_number}',
        max_page: null,
        paged: function (page) {
            $("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page", page);
            _Instance.FetchForPage(page);
        }
    });

    window.laydate.render({
        elem: '#Begin',
        theme: '#393D49',
        trigger: 'click'
    });
    window.laydate.render({
        elem: '#End',
        theme: '#393D49',
        trigger: 'click'
    });
    _Instance.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
}